package br.com.roteador.component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.enterprise.context.ApplicationScoped;

import br.com.caelum.vraptor.Convert;
import br.com.caelum.vraptor.converter.Converter;

@Convert(Date.class)
@ApplicationScoped
public class DateConversor implements Converter<Date> {

	public Date convert(String value, Class<? extends Date> arg1) {
		if (!"".equals(value)) {
	        try {
	            return new SimpleDateFormat("dd/MM/yyyy").parse(value);
	        } catch (ParseException e) {
	            //e.printStackTrace();
	            return null;
	        }
		} else {
			return null;
		}
    }
	
}